package difed.restaurante.db;


import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DbRestaurant  extends SQLiteOpenHelper {
    
    private static final String DATABASE_NAME = "misrestaurantes.db";
    private static final int DATABASE_VERSION = 2;
    
    public final static String TABLA_RESTAURANTES = "restaurantes";
    public final static String TABLA_FILTRO = "filtro";
    public static final String TABLA_TIPO = "tipo";
    public static final String TABLA_POBLACION = "poblacion";
    public static final String TABLA_PROVINCIA = "provincia";
    public static final String COL_ID = "id";
    public static final String COL_NOMBRE = "nombre";
    public static final String COL_DIRECCION = "direccion";
    public static final String COL_TELEFONO1 = "telefono1";
    public static final String COL_TELEFONO2 = "telefono2";
    public static final String COL_POBLACION = "poblacion";
    public static final String COL_PROVINCIA = "provincia";
    public static final String COL_TIPO = "tipo";
    public static final String COL_SUGERENCIAS = "sugerencias";
    public static final String COL_NOTAS = "notas";
    
    private static ProveedorBDImpl db;
    
    
    public DbRestaurant(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
       
    }
    
    

    @Override
    public void onCreate(SQLiteDatabase db) {
        // Tabla restaurantes
        String sql = "CREATE TABLE IF NOT EXISTS " + TABLA_RESTAURANTES + " ("
                    + COL_ID        + " INTEGER PRIMARY KEY AUTOINCREMENT, "
                    + COL_NOMBRE    + " TEXT NOT NULL, " 
                    + COL_DIRECCION      + " TEXT, " 
                    + COL_TELEFONO1    + " TEXT, "
                    + COL_TELEFONO2    + " TEXT, "
                    + COL_POBLACION   + " TEXT, "
                    + COL_PROVINCIA   + " TEXT, "
                    + COL_TIPO   + " TEXT, "
                    + COL_SUGERENCIAS   + " TEXT, "
                    + COL_NOTAS  + " TEXT);";
        db.execSQL(sql);
        
     // Tabla poblacion
        sql = "CREATE TABLE IF NOT EXISTS " + TABLA_POBLACION + " ("
                    + COL_ID        + " INTEGER PRIMARY KEY AUTOINCREMENT, "
                    + COL_POBLACION    + " TEXT NOT NULL);";
        db.execSQL(sql);
        
        
     // Tabla provincia
        sql = "CREATE TABLE IF NOT EXISTS " + TABLA_PROVINCIA + " ("
                    + COL_ID        + " INTEGER PRIMARY KEY AUTOINCREMENT, "
                    + COL_PROVINCIA    + " TEXT NOT NULL);";
        db.execSQL(sql);
        
        
     //Tabla tipo
        sql = "CREATE TABLE IF NOT EXISTS " + TABLA_TIPO + " ("
                    + COL_ID        + " INTEGER PRIMARY KEY AUTOINCREMENT, "
                    + COL_TIPO    + " TEXT NOT NULL);";
        db.execSQL(sql);
        
        
        //Tabla filtro 1
        sql = "CREATE TABLE IF NOT EXISTS " + TABLA_FILTRO + " ("
            + COL_ID        + " INTEGER PRIMARY KEY AUTOINCREMENT, "
            + COL_NOMBRE    + " TEXT NOT NULL, " 
            + COL_DIRECCION      + " TEXT, " 
            + COL_TELEFONO1    + " TEXT, "
            + COL_TELEFONO2    + " TEXT, "
            + COL_POBLACION   + " TEXT, "
            + COL_PROVINCIA   + " TEXT, "
            + COL_TIPO   + " TEXT, "
            + COL_SUGERENCIAS  + " TEXT, "
            + COL_NOTAS  + " TEXT);";
        db.execSQL(sql);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        onCreate(db);
    }
    
    

}
